package cn.jjxx.modules.iface.controller;

import cn.jjxx.core.model.AjaxJson;
import cn.jjxx.core.query.wrapper.EntityWrapper;
import cn.jjxx.core.utils.StringUtils;
import cn.jjxx.modules.project.entity.LocationOfProvinces;
import cn.jjxx.modules.project.entity.ProjectDistributionManagement;
import cn.jjxx.modules.project.service.ILocationOfProvincesService;
import cn.jjxx.modules.project.service.IProjectDistributionManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @Description: .<br>
 * @author: Administrator .<br>
 * @date: 2021/3/16 0016<br>
 */


@Controller
@RequestMapping("/iface/roadbridgeproject")
public class RoadBridgeProjectController {

    @Autowired
    protected IProjectDistributionManagementService projectDistributionManagementService;
    @Autowired
    protected ILocationOfProvincesService locationOfProvincesService;


    /**
     * @Description: 获取当前所有项目总数和合同金额 .<br>
     * @author zx .<br>
     * @date 2021-3-17<br>
     */
    @RequestMapping(value = "/getTotal", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public AjaxJson getTotal() {
        AjaxJson ajaxJson = new AjaxJson();
        EntityWrapper<ProjectDistributionManagement> entityWrapper = new EntityWrapper<ProjectDistributionManagement>(ProjectDistributionManagement.class);
        List<ProjectDistributionManagement> list = projectDistributionManagementService.selectTotal(entityWrapper);
        ajaxJson.setData(list);
        return ajaxJson;
    }



    /**
     * @Description: 获取项目列表信息 .<br>
     * @author zx .<br>
     * @date 2021-3-17<br>
     */
    @RequestMapping(value = "/getDetailList",method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public AjaxJson getDetailList(){
        AjaxJson ajaxJson = new AjaxJson();
        LinkedHashMap<String, Object> extend = new LinkedHashMap<String, Object>();
        try {
            //项目基本信息-projectdistributionmanagement
            EntityWrapper<ProjectDistributionManagement> entityWrapper = new EntityWrapper<ProjectDistributionManagement>(ProjectDistributionManagement.class);
            List<ProjectDistributionManagement> list = projectDistributionManagementService.selectList(entityWrapper);
            extend.put("projectdistributionmanagement", list);
            ajaxJson.setExtend(extend);
        } catch(Exception e) {
            ajaxJson.fail("操作失败");
            e.printStackTrace();
        }
        return ajaxJson;
    }


    /**
     * @Description: 获取各省份项目数 .<br>
     * @author zx .<br>
     * @date 2021-3-17<br>
     */
    @RequestMapping(value = "/getProvice", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public AjaxJson getProvice() {
        AjaxJson ajaxJson = new AjaxJson();
        EntityWrapper<ProjectDistributionManagement> entityWrapper = new EntityWrapper<ProjectDistributionManagement>(ProjectDistributionManagement.class);
        List<ProjectDistributionManagement> list = projectDistributionManagementService.selectDetail(entityWrapper);
        ajaxJson.setData(list);
        return ajaxJson;
    }


    /**
     * @Description: 获取当前省份所有项目总数和合同金额合计 .<br>
     * @author zx .<br>
     * @date 2021-3-17<br>
     */
    @RequestMapping(value = "/getDetails", method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson getDetails(String provinceCode) {
        AjaxJson ajaxJson = new AjaxJson();
        ajaxJson.setMsg("提交成功");
        try {
            LocationOfProvinces locationOfProvinces = locationOfProvincesService.selectQuantity(provinceCode);
            ajaxJson.setData(locationOfProvinces);
        } catch (Exception e) {
            ajaxJson.fail("操作失败");
            e.printStackTrace();
        }
        return ajaxJson;
    }


    /**
     * @Description: 获取当前省份所有项目列表信息 .<br>
     * @author zx .<br>
     * @date 2021-3-17<br>
     */
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ResponseBody
    public AjaxJson getAll(String provinceCode,String cityCode) {
        AjaxJson ajaxJson = new AjaxJson();
        ajaxJson.setMsg("提交成功");
        try {
            if(StringUtils.isBlank(cityCode)){
                cityCode = null;
            }
            List<LocationOfProvinces> list = locationOfProvincesService.selectInfo(provinceCode,cityCode);
            ajaxJson.setData(list);
        } catch (Exception e) {
            ajaxJson.fail("操作失败");
            e.printStackTrace();
        }
        return ajaxJson;
    }

    /**
     * @Description: 获取各市项目数 .<br>
     * @author zx .<br>
     * @date 2021-4-9<br>
     */
    @RequestMapping(value = "/getCity", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public AjaxJson getCity(String provinceCode) {
        AjaxJson ajaxJson = new AjaxJson();
        ajaxJson.setMsg("提交成功");
        try {
            List<LocationOfProvinces> list = locationOfProvincesService.selectCity(provinceCode);
            ajaxJson.setData(list);
        } catch (Exception e) {
            ajaxJson.fail("操作失败");
            e.printStackTrace();
        }
        return ajaxJson;
    }

    /**
     * @Description: 获取项目访问路径 .<br>
     * @author zx .<br>
     * @date 2021-3-17<br>
     */
    @RequestMapping(value = "/getUrl", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public AjaxJson getUrl(HttpServletRequest request,
                             HttpServletResponse response) {
        AjaxJson ajaxJson = new AjaxJson();
        String url = request.getScheme() + "://" +request.getServerName();
        ajaxJson.setData(url);
        return ajaxJson;
    }
}
